import request from '@/utils/request'

// 查询圈子列表
export function listTopic(query) {
  return request({
    url: '/system/topic/list',
    method: 'get',
    params: query
  })
}

// 查询圈子详细
export function getTopic(topicId) {
  return request({
    url: '/system/topic/' + topicId,
    method: 'get'
  })
}

// 新增圈子
export function addTopic(data) {
  return request({
    url: '/system/topic',
    method: 'post',
    data: data
  })
}

// 修改圈子
export function updateTopic(data) {
  return request({
    url: '/system/topic',
    method: 'put',
    data: data
  })
}

// 删除圈子
export function delTopic(topicId) {
  return request({
    url: '/system/topic/' + topicId,
    method: 'delete'
  })
}

// 导出圈子
export function exportTopic(query) {
  return request({
    url: '/system/topic/export',
    method: 'get',
    params: query
  })
}

// 修改圈子状态
export function changeTopicStatus(topicId, status) {
  const data = {
    topicId,
    status
  }
  return request({
    url: '/system/topic/changeStatus',
    method: 'put',
    data: data
  })
}

// 查询圈子成员列表
export function listTopicMembers(topicId, query) {
  return request({
    url: '/system/topic/' + topicId + '/members',
    method: 'get',
    params: query
  })
}

// 移除圈子成员
export function removeTopicMember(topicId, userId) {
  return request({
    url: '/system/topic/' + topicId + '/members/' + userId,
    method: 'delete'
  })
}

// 设置成员角色
export function setMemberRole(topicId, userId, role) {
  const data = {
    role
  }
  return request({
    url: '/system/topic/' + topicId + '/members/' + userId + '/role',
    method: 'put',
    data: data
  })
}

// 禁言/解除禁言成员
export function toggleMemberMute(topicId, userId, isMuted) {
  const data = {
    isMuted
  }
  return request({
    url: '/system/topic/' + topicId + '/members/' + userId + '/mute',
    method: 'put',
    data: data
  })
}